package com.ht.controller;

import cn.hutool.core.bean.BeanUtil;

import com.ht.data.Result;
import com.ht.domain.bo.*;
import com.ht.domain.po.TbDoctor;
import com.ht.domain.po.TbKnowledge;
import com.ht.domain.vo.*;
import com.ht.dto.TbDepartmentDTO;
import com.ht.dto.TbDoctorDTO;
import com.ht.feign.ExpertOutpatientFeign;
import com.ht.feign.PublicOutpatientFeign;
import com.ht.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.ArrayStack;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController  //等于@Restquest + @Controller
@RequestMapping("/experts")
@Api("专家门诊挂号管理系统")
@RefreshScope  //实时刷新
public class ExpertsController {

    @Autowired
    private TbProvincesService tbProvincesService;

    @Autowired
    private TbCitiesService tbCitiesService;

    @Autowired
    private PublicOutpatientFeign publicOutpatientFeign;

    @Autowired
    private TbJuniorService tbJuniorService;

    @Autowired
    private TbDoctorService tbDoctorService;

    @Autowired
    private ExpertOutpatientFeign expertOutpatientFeign;

    @Autowired
    private TbDepartmentService tbDepartmentService;

    @Autowired
    private TbKnowledgeService tbKnowledgeService;

    //省
    @GetMapping("/queryByProvince")
    @ApiOperation("查询所有省")
    @ApiImplicitParam()
    public Result queryByProvince(){
        List<TbProvincesBO> list = tbProvincesService.queryByProvince();
        List<TbProvincesVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbProvincesVO  vo = new TbProvincesVO();
            BeanUtil.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }
    //根据省id查询对应的市
    @GetMapping("/queryByCity/{provinceId}")
    @ApiOperation("根据省id查询对应的市")
    @ApiImplicitParam()
    public Result queryByCity(@PathVariable("provinceId") Long provinceId){
        List<TbCitiesBO> list = tbCitiesService.queryByCity(provinceId);
        List<TbCitiesVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbCitiesVO vo = new TbCitiesVO();
            BeanUtil.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }

    //查询所有科室
    @GetMapping("/queryByDepartment")
    @ApiOperation("查询所有科室")
    @ApiImplicitParam()
    public Result queryByDepartment(){
        Result all = publicOutpatientFeign.findDepartmentAll();
        return all;
    }

    //根据科室id查询所有对应的专科表
    @GetMapping("/queryByJunior/{departmentId}")
    @ApiOperation("根据科室id查询所有对应的专科表")
    @ApiImplicitParam()
    public Result queryByJunior(@PathVariable("departmentId") Long departmentId){
        List<TbJuniorBO> list = tbJuniorService.queryByJunior(departmentId);
        List<TbJuniorVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbJuniorVO vo = new TbJuniorVO();
            BeanUtil.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }
    
    //根据专科id查询所有对应的疾病
    @GetMapping("/queryJuniorByjuniortId/{juniorId}")
    @ApiOperation("根据专科id查询所有对应的疾病")
    @ApiImplicitParam()
    public Result queryJuniorByjuniortId(@PathVariable("juniorId") Long juniorId){
        List<TbKnowledgeBO> list = tbKnowledgeService.queryJuniorByjuniortId(juniorId);
        List<TbKnowledgeVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbKnowledgeVO vo = new TbKnowledgeVO();
            BeanUtil.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }


    //根据科室id查询所有对应的专科表

    /**
     *
     * @param departmentId  科室id
     * @param status        分类查询的状态    0/出诊医生优先    1/价格从高到低  2/价格从低到高
     * @return
     */
    @PostMapping("/queryDoctorBydepartmentIdAndStatus/{departmentId}/{status}/{levelId}/{score}")
    @ApiOperation("根据科室id查询所有对应的医生表")
    @ApiImplicitParam()
    public Result queryDoctorBydepartmentIdAndStatus(@PathVariable("departmentId") Long departmentId,@PathVariable("status") Integer status,@PathVariable("levelId") Long levelId,@PathVariable("score")Long score){
        List<TbDoctorBO> list = tbDoctorService.queryDoctorBydepartmentIdAndStatus(departmentId, status,levelId,score);
        List<TbDoctorVO> listt =  new ArrayList<>();
        list.forEach(obj->{
            TbDoctorVO vo = new TbDoctorVO();
            BeanUtil.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }

//    //根据科室id查询所有对应的专科表
//
//    /**
//     *
//     * @param departmentId  科室id
//     * @return
//     */
//    @GetMapping("/queryDoctorBydepartmentId/{departmentId}")
//    @ApiOperation("根据科室id查询所有对应的医生表")
//    @ApiImplicitParam()
//    public Result queryDoctorBydepartmentId(@PathVariable("departmentId") Long departmentId){
//        TbDepartmentBO tbDepartmentBO = tbDepartmentService.queryTbDepartmentBydepartmentId(departmentId);
//        Result result = expertOutpatientFeign.queryDepartmentBydepartmentName(tbDepartmentBO.getDepartmentName());
//        return result;
//    }

    @GetMapping("/queryDoctorByFuzzy")
    @ApiOperation("根据疾病/医生/科室/医院模糊查询所有对应的医生表")
    @ApiImplicitParam()
    public Result queryDoctorByFuzzy(String name,@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "8") Integer pageSize){
        List<TbDoctorBO> list = tbDoctorService.queryDoctorByFuzzy(name, pageNum, pageSize);
        List<TbDoctorVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbDoctorVO vo = new TbDoctorVO();
            BeanUtils.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }











}
